import moment from 'moment';

// 更新 moment 的默认语言环境
moment.updateLocale('zh-cn', {
    relativeTime : {
        future: "%s内",
        past:   "%s前",
        s  : '几秒',
        ss : '%d秒',
        m:  "1分钟",
        mm: "%d分钟",
        h:  "1小时",
        hh: "%d小时",
        d:  "1天",
        dd: "%d天",
        M:  "1个月",
        MM: "%d月",
        y:  "1年",
        yy: "%d年"
    }
})

function momentFormatYear(date: Date, format: string = 'YYYY') {
    return moment(date).format(format)
}

function momentFormatYearMonth(date: Date, format: string = 'YYYY.MM') {
    return moment(date).format(format)
}

function momentFromNow(date: string) {
    return moment(date).fromNow()
}

export { momentFormatYear, momentFromNow, momentFormatYearMonth}
